﻿using UnityEngine;
using System.Collections;
using System.Linq; 
using System.IO;

public class CSVReader : MonoBehaviour 
{
	public TextAsset csvFile;
	private string[,] m_grid = new string[60,60];
	private bool m_hasParsed = false;
	public int m_level;
	public void Start()
	{
	}

	public void Parse(TileType _tileType)
	{
		int i = 0, j = 0;
		string fileName = "Assets/TileMap/Level";
		m_level = SceneInformation.GetInstance().m_level;
		if( _tileType == TileType.TILE_64x64 )
		{
			fileName += m_level + "_64.txt";
		}
		else if( _tileType == TileType.TILE_32x32 )
		{
			fileName += m_level + "_32.txt";
		}
		foreach (string line in File.ReadAllLines(fileName))
		{
			string[] parts = line.Split(',');
			foreach (string part in parts)
			{
				m_grid[i,j] = part;
				j++;
			}
			i++;
			j = 0;
		}
		m_hasParsed = true;
	}

	public string[,] GetGrid()
	{
		return m_grid;
	}
	public bool HasParsed()
	{
		return m_hasParsed;
	}

}
